﻿using System.Collections.Generic;

public class ContentManager
{
    private Stack<UIBaseContent> contents = new Stack<UIBaseContent>();

    public void Push(UIBaseContent content)
    {
        if(contents.Count != 0)
        {
            UIBaseContent baseContent = contents.Peek();
            UIBaseView baseView = Singleton<UIManager>.GetInstance().GetSingleUI(baseContent.ContentType).GetComponent<UIBaseView>();
            baseView.OnPause(baseContent);
        }
        contents.Push(content);
        UIBaseView view = Singleton<UIManager>.GetInstance().GetSingleUI(content.ContentType).GetComponent<UIBaseView>();
        view.OnEnter(content);
    }
    public void Pop()
    {
        if(contents.Count != 0)
        {
            UIBaseContent baseContent = contents.Pop();
            UIBaseView baseView = Singleton<UIManager>.GetInstance().GetSingleUI(baseContent.ContentType).GetComponent<UIBaseView>();
            baseView.OnExit(baseContent);
        }

        if(contents.Count != 0)
        {
            UIBaseContent baseContent = contents.Peek();
            UIBaseView baseView = Singleton<UIManager>.GetInstance().GetSingleUI(baseContent.ContentType).GetComponent<UIBaseView>();
            baseView.OnResume(baseContent);
        }
    }
    public UIBaseContent PeekOrNull()
    {
        if (contents.Count == 0)
            return null;
        return contents.Peek();
    }
    
}
